#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	int n;
	int arr[1000][3];
	int sum[10000] = {0};
	int count = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			scanf("%d",&arr[i][j]);
			sum[i] = sum[i]+arr[i][j];
		}
	}
	for (int j = 0; j < n; j++)
	{
		for (int i = j + 1; i < n; i++)
		{
			if (abs(arr[j][1] - arr[i][1]) <= 5 &&
				abs(arr[j][2] - arr[i][2]) <= 5 &&
				abs(arr[j][3] - arr[i][3]) <= 5 &&
				abs(sum[j] - sum[i]) <= 5)
				count++;
		}
	}

	printf("%d",count);
	return 0;
}